package com.varian.service.exception.handler;

import com.varian.tool.contant.ResultConstant;
import com.varian.tool.exception.ServerException;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import jakarta.servlet.http.HttpServletResponse;

/**
 * @author ben
 * @since 2024/6/27
 */
public class ServerExceptionHandler implements ExceptionHandlerStrategy {
    @Override
    public Class<? extends Exception> getExceptionClass() {
        return ServerException.class;
    }

    @Override
    public IR handle(Exception exception, HttpServletResponse response) {
        ServerException serverException = (ServerException) exception;
        return R.result(serverException.getStatus(), ResultConstant.FAIL_CODE, exception.getMessage(), null);
    }
}
